package com.dw.etl.core.service;

import com.dw.etl.common.util.UUIDUtil;
import  com.dw.etl.common.vo.PaginationVO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import com.dw.etl.core.api.MdBaseIndexService;
import com.dw.etl.core.mapper.MdBaseIndexMapper;
import com.dw.etl.core.bean.model.MdBaseIndex;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

/**
 * mdBaseIndex服务实现类
 * Created by hozeData on 2021/07/05.
 */
@Service
@Transactional
public class MdBaseIndexServiceImpl implements MdBaseIndexService{

    private static final Logger LOGGER = LoggerFactory.getLogger(MdBaseIndexServiceImpl.class);

    @Autowired
    private MdBaseIndexMapper mdBaseIndexMapper;

    @Override
    public int insert(MdBaseIndex mdBaseIndex) {
        if(StringUtils.isEmpty(mdBaseIndex.getIdIndex())){
            String uuid32 = UUIDUtil.getUUID32();
            mdBaseIndex.setIdIndex(uuid32);
        }
        return mdBaseIndexMapper.insert(mdBaseIndex);
    }

    @Override
    public int insertSelective(MdBaseIndex mdBaseIndex)  {
        if(StringUtils.isEmpty(mdBaseIndex.getIdIndex())){
            String uuid32 = UUIDUtil.getUUID32();
            mdBaseIndex.setIdIndex(uuid32);
        }
        return mdBaseIndexMapper.insertSelective(mdBaseIndex);
    }

    @Override
    public int deleteById(String pkIndex)  {
        return mdBaseIndexMapper.deleteByPrimaryKey(pkIndex);
    }

    @Override
    public int updateByIdSelective(MdBaseIndex mdBaseIndex)  {

        return mdBaseIndexMapper.updateByPrimaryKeySelective(mdBaseIndex);
    }

    @Override
    public int updateById(MdBaseIndex mdBaseIndex)  {
        return mdBaseIndexMapper.updateByPrimaryKey(mdBaseIndex);
    }

    @Override
    public MdBaseIndex getById(String pkIndex)  {
        return mdBaseIndexMapper.selectByPrimaryKey(pkIndex);
    }

    @Override
    public List<MdBaseIndex> findByModel(MdBaseIndex mdBaseIndex)  {
        return mdBaseIndexMapper.findByModel(mdBaseIndex);
    }

    @Override
    public PaginationVO<MdBaseIndex> findPageByModel(MdBaseIndex mdBaseIndex, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum == null? 1 : pageNum, pageSize == null? 10 : pageSize);
        List<MdBaseIndex> quesList = mdBaseIndexMapper.findByModel(mdBaseIndex);
        PageInfo<MdBaseIndex> pageInfo = new PageInfo<>(quesList);
        PaginationVO<MdBaseIndex> paginationVo = new PaginationVO(pageInfo.getTotal(), pageInfo.getList());
        return paginationVo;
    }

    @Override
    public PaginationVO<MdBaseIndex> findByLike(String filter, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum == null? 1 : pageNum, pageSize == null? 10 : pageSize);
        List<MdBaseIndex> quesList = mdBaseIndexMapper.findByLike(filter);
        PageInfo<MdBaseIndex> pageInfo = new PageInfo<>(quesList);
        PaginationVO<MdBaseIndex> paginationVo = new PaginationVO(pageInfo.getTotal(), pageInfo.getList());
        return paginationVo;
    }
}
